package com.example.plane.GameView;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.util.DisplayMetrics;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;

import com.example.plane.GameActivity;
import com.example.plane.R;

import static com.example.plane.GameActivity.resourcesInstance;

public class background  {

        public Thread th;
        public Canvas canvas ;
        public  int[] currX=new int[2];
        public  int[] currY=new int[2];
        public  int[] bgwidth=new int[2];
        public  int[] bgheight=new int[2];
        public  float[] scaleWidth=new float[2];
        public  float[] scaleHeight=new float[2];
        public  Paint p = new Paint();//拿到画笔
        public  int fristpass=2;
        public Bitmap[] bitmap=new Bitmap[fristpass];
        private boolean surfaceAvailable;
    public background( )
    {

    }
        public void  initView()
        {

                //获取窗口管理器
//         bgwidth = wm.getDefaultDisplay().getWidth();
//         bgheight = wm.getDefaultDisplay().getHeight();
//        WindowManager windowManager = GameActivity.instance.getWindowManager();
//        Display display = windowManager.getDefaultDisplay();
//
//        //Andorid.util 包下的DisplayMetrics 类提供了一种关于显示的通用信息，如显示大小，分辨率和字体
//        DisplayMetrics metrics = new DisplayMetrics();
                //将当前窗口中的一些信息放在DisplayMetrics里面
//        display.getMetrics(metrics);
//                WindowManager wm = getWindowManager();;//获取窗口管理器服务以及场景
                for (int i = 0; i < fristpass; i++) {
                        bitmap[i] = BitmapFactory.decodeResource(GameActivity.resourcesInstance, R.drawable.qj0);
                        bgwidth[i] = bitmap[i].getWidth();
                        bgheight[i] = bitmap[i].getHeight();
                        scaleWidth[i] = ((float)GameActivity.Scrrenwidth)/ bgwidth[i];//计算宽度的缩放比例
                        scaleHeight[i] = ((float) GameActivity.Screenheight)/ bgheight[i];//计算高度的缩放比例
                        Matrix matrix = new Matrix();//矩阵类用于图像坐标的转换，以及旋转，缩放等特殊操作。
                        matrix.postScale(scaleWidth[i], scaleHeight[i]);//设置缩放
                        //如果将实例化在外面即不释放内存，该对象会一直缩放
                        bitmap[i] = Bitmap.createBitmap(bitmap[i], 0, 0, bgwidth[i], bgheight[i], matrix, false);//创建一个缩放后的图片
                }
                currX[0]=0;
                currY[0]=0;
                currX[1]=0;;
                currY[1]=-bitmap[1].getHeight();
                System.out.println(currY[1]);
        }
        public void doDraw(Canvas canvas )
        {
                for(int i=0;i<fristpass;i++) {
                        canvas.drawBitmap(bitmap[i],currX[i], currY[i], p);
                }
        }
    public void bglogic()
    {
        currY[0]=currY[0]+10;
        currY[1]=currY[1]+10;;

        for(int i=0;i<fristpass;i++)
        {
            if (currY[i] >= bitmap[i].getHeight()) {
                currY[i] = -bitmap[i].getHeight();
            }
        }
    }


        }
